package edu.dayu.controller;

import edu.dayu.pojo.ArticleType;
import edu.dayu.service.ArticleTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("/admin")
public class ArticleTypeController {
    @Autowired
    private ArticleTypeService articleTypeService;

    @PostMapping("/articleTypeList")
    public List<ArticleType> articleTypeList (ArticleType articleType){
        return  articleTypeService.articleTypeList(articleType);
    }

    @PostMapping("/articleTypeInsert")
    public void articleTypeInsert(ArticleType articleType){
        articleTypeService.articleTypeInsert(articleType);
    }

    @PostMapping("/articleTypeUpdate")
    public void articleTypeUpdate(ArticleType articleType){
        articleTypeService.articleTypeUpdate(articleType);
    }

    @PostMapping("/articleTypeById")
    public ArticleType articleTypeById(ArticleType articleType){
        List<ArticleType> articleTypes = articleTypeService.articleTypeList(articleType);
        ArticleType articleType1 = new ArticleType();
        for (ArticleType type : articleTypes) {
            articleType1 = type;
        }
        return articleType1;
    }

    @PostMapping("/articleTypeDelete")
    public void articleTypeDelete(ArticleType articleType){
        articleTypeService.articleTypeDelete(articleType);
    }
}
